--- title: "移动距离" created: 2025-11-28 tags: - 算法 --- # 移动距离 ## 题目 [移动距离](https://www.acwing.com/problem/content/1221/) ![[image-fe110884.png]] ## 思路分析 模拟案例可以发现规律 ![[image-c6955978.png]] ```cpp #include using namespace std; int main(){ int w,m,n; cin>>w>>m>>n; int zong1=m/w; // cout<<"zong1: "< using namespace std; int main(){ int w,m,n; cin>>w>>m>>n; m--,n--; int col1=m/w; int row1=m%w; if(col1&1) row1=w-1-row1; int col2=n/w; int row2=n%w; if(col2&1) row2=w-1-row2; cout<